#include "dockLabel.h"

bool DockLabel::_isShow = false;

DockLabel::DockLabel()
{
    this->_isShow = false;
    this->setParent(nullptr);

    this->setAlignment(Qt::AlignCenter);

    this->setStyleSheet("background: rgba(0,0,0,0);\nborder-radius: 5px;\ncolor: rgba(255, 255, 255, 0);");
    this->hide();
    this->setWindowFlags(Qt::WindowStaysOnTopHint);


}

DockLabel& DockLabel::I(){
    static DockLabel instance;
    return instance;
}



void DockLabel::show(QString text, QWidget* parent){

    qDebug() << "DockLable.show()";

    if(_isShow){
        qDebug() << "DockLable.isShow()";
        return;
    }
    _isShow = true;

    this->raise();

    this->setParent(parent);
    if(this->parent()){
        this->setGeometry(parent->width()/2-150, parent->height()/2-25, 300, 50);
    }
    this->setMaximumHeight(50);
    this->setMaximumWidth(300);

    this->setText(text);
    QWidget::show();

    for(int time = 10; time < 200; time += 20){
        QTimer::singleShot(time, [this, time](){
            this->setStyleSheet("background: rgba(0,0,0," + QString::number(time/500.0) + ");\nborder-radius: 5px; \ncolor:rgba(255, 255, 255, " + QString::number(time/230.0)  +")");
        });
    }

    QTimer::singleShot(800, [this](){
        for(int time = 10; time < 200; time += 40){
            QTimer::singleShot(time, [this, time](){
                this->setStyleSheet("background: rgba(0,0,0," + QString::number((200.0-time)/500.0) + ");\nborder-radius: 5px;\ncolor:rgba(255, 255, 255, " + QString::number((200-time)/230.0)  +")");
            });
        }
        QTimer::singleShot(200, [this](){
            QWidget::hide();
            setWindowFlags(Qt::WindowStaysOnTopHint);
            _isShow = false;
        });
    });
}

void DockLabel::hide(){

}
